/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package redis.client;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

/**
 *
 * @author chieu
 */
public class ValidatePhonePubSubClient {

    private static final Logger logger = Logger.getLogger(ValidatePhonePubSubClient.class);
    private static final Jedis jedis;

    static {
        jedis = new Jedis(REDIS_CONF.HOST, REDIS_CONF.PORT);
        jedis.select(REDIS_CONF.WEBSERVICE_DB);
    }

    public static void addPhone(int id) {
        if (id < 1) {
            return;
        }
        JSONObject message = new JSONObject();
        message.put("id", id);
        message.put("type", "add");
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.VALIDATE_PHONE, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }

    }

    public static void updatePhone(int id) {
        if (id < 1) {
            return;
        }
        JSONObject message = new JSONObject();
        message.put("id", id);
        message.put("type", "update");
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.VALIDATE_PHONE, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }

    }

    public static void deletePhone(int id) {
        if (id < 1) {
            return;
        }
        JSONObject message = new JSONObject();
        message.put("id", id);
        message.put("type", "delete");
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.VALIDATE_PHONE, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }

    }

    public static void changeQuantity(List<Integer> listId) {
        if (listId == null || listId.isEmpty()) {
            return;
        }
        JSONObject message = new JSONObject();
        message.put("listId", listId);
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.APPROVE_ORDER, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }

    }
    
    public static void changeCategory() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_CATEGORY, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    public static void changeStore() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_STORE, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    public static void changeProvince() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_PROVINCE, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    public static void changeDistrict() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_DISTRICT, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    public static void changePromotion() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_PROMOTION, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    public static void changeColor() {
        JSONObject message = new JSONObject();
        try {
            jedis.publish(REDIS_PUBSUB_CHANNEL.CHANGE_COLOR, message.toString());
        } catch (Exception ex) {
            logger.error(ex);
        }
    }

    public static void main(String[] args) {
        List<Integer> listId = new ArrayList();
        listId.add(279);
        listId.add(252);
//        changeQuantity(listId);
//        changeCategory();
//        changeDistrict();
//        changePromotion();
//        changeProvince();
        changeStore();
    }
}
